package omg.loot;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class KeyReader implements KeyListener {
   //N�pp�inpuskurit:
   boolean ylos = false;
   boolean alas = false;
   boolean vasen = false;
   boolean oikea = false;
   boolean space = false;
   GameRunnable main; //Viite p��ohjelmaan

   public KeyReader(final GameRunnable maintemp) {
      this.main = maintemp;
   }
   
   public void keyPressed(final KeyEvent e) {
      switch (e.getKeyCode()) {
         case KeyEvent.VK_UP: case KeyEvent.VK_W://Nuolinäppäin ylös
            ylos = true;
            break;

         case KeyEvent.VK_DOWN: case KeyEvent.VK_S: //Nuolinäppäin oikea
            alas = true;
            break;

         case KeyEvent.VK_LEFT: case KeyEvent.VK_A: //Nuolinäppäin vasen
            vasen = true;
            break;

         case KeyEvent.VK_RIGHT: case KeyEvent.VK_D: //Nuolinäppäin oikea
            oikea = true;
            break;

         case KeyEvent.VK_SPACE: //Space
            space = true;
            break;
            
         case KeyEvent.VK_ESCAPE: //Escape
            System.exit(0);
            break;      
      }
   }

   public void keyReleased(final KeyEvent e) {
      switch (e.getKeyCode()) {
         case KeyEvent.VK_UP: case KeyEvent.VK_W://Nuolin�pp�in yl�s
            ylos = false;
            break;

         case KeyEvent.VK_DOWN: case KeyEvent.VK_S: //Nuolin�pp�in oikea
            alas = false;
            break;

         case KeyEvent.VK_LEFT: case KeyEvent.VK_A: //Nuolin�pp�in vasen
            vasen = false;
            break;

         case KeyEvent.VK_RIGHT: case KeyEvent.VK_D: //Nuolin�pp�in oikea
            oikea = false;
            break;

         case KeyEvent.VK_P: //Pause
            if (main.pause) { //Jos ollaan jo pausella:
               main.pause = false; //Unpausetetaan
            }
            else //Jos ei olla pausella:
               main.pause = true; //Pausetetaan
            break;

         case KeyEvent.VK_SPACE: //Space
            space = false;
            break;
           
      }
   }

   public void keyTyped(final KeyEvent e) {}
}